package com.jnr.huatu.view;

import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * 模糊效果
 * @author：景辉
 * created at 2017/2/8 0008 上午 10:50
 */

public class BlurMaskFilterView extends View {
    public BlurMaskFilterView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 创建绘画方法
     * @author：景辉
     * created at 2017/2/8 0008 上午 11:15
     */
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        BlurMaskFilter bmf = null;
        Paint paint = new Paint();//创建画笔
        paint.setAntiAlias(true);//防止边缘锯齿
        paint.setColor(Color.RED);//设置画笔颜色为红色
        paint.setStyle(Paint.Style.FILL);//画笔风格

        paint.setTextSize(68);//设置字体大小
        paint.setStrokeWidth(5);//画笔粗细

        bmf = new BlurMaskFilter(10f,BlurMaskFilter.Blur.NORMAL);
        paint.setMaskFilter(bmf);
        canvas.drawText("我是Mr.JH",100,100,paint);

        bmf = new BlurMaskFilter(10f,BlurMaskFilter.Blur.OUTER);
        paint.setMaskFilter(bmf);
        canvas.drawText("我是Mr.JH",100,200,paint);

        bmf = new BlurMaskFilter(10f,BlurMaskFilter.Blur.INNER);
        paint.setMaskFilter(bmf);
        canvas.drawText("我是Mr.JH",100,300,paint);

        bmf = new BlurMaskFilter(10f,BlurMaskFilter.Blur.SOLID);
        paint.setMaskFilter(bmf);
        canvas.drawText("我是Mr.JH",100,400,paint);

        setLayerType(View.LAYER_TYPE_SOFTWARE,null);//关闭硬件加速
    }
}
